from importlib import import_module

import coin.strategy.mm.tool.archive_base as abase
from coin.strategy.interval.alpha import (load_recent_df, get_relation_cross)

from flask import Flask, current_app, render_template

flaskapp = Flask(__name__)


@flaskapp.route('/')
def plot():
  total_df = load_recent_df()
  module_path = 'coin.strategy.interval.alphas.basis.basis_1'
  p, m = module_path.rsplit('.', 1)
  alpha_func = getattr(import_module(p), m)
  # get_relation_cross(total_df, 'okex-btcusd-perpetual', 'okex-btcusd-perpetual', alpha_func, interval_mins=5)
  # get_relation_cross(total_df, 'bitmex-xbtusd', 'bitmex-xbtusd', alpha_func, interval_mins=5)
  img_path = get_relation_cross(total_df,
                                'okex-btcusd-nextweek',
                                'okex-btcusd-quarter',
                                alpha_func,
                                interval_mins=5)
  flaskapp.config['filepath'] = img_path
  return render_template('index.html', plot_img_path=current_app.config['filepath'])


flaskapp.run(debug=True, port=5882, host='0.0.0.0')
